package com.hs.jhzd.controller;

import com.hs.jhzd.entity.ZfYyjlbEntity;
import com.hs.jhzd.repository.ZfYyjlbRepository;
import com.hs.jhzd.utils.ToolUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

@RequestMapping("/acp-cloud/order")
@Controller
public class ZfYyjlbController {

    @Autowired
    private ZfYyjlbRepository repository;


    @RequestMapping("/findByJsbh/list")
    @ResponseBody
    public List<ZfYyjlbEntity> findByJsbh(String jsbh) {
        return repository.findByJsbh(jsbh);
    }

    @RequestMapping("/findByRybh/list")
    @ResponseBody
    public List<ZfYyjlbEntity> findByRybh(String jsbh, String rybh) {
        return repository.findByJsbhAndRybh(jsbh, rybh);
    }

    @RequestMapping("/findDoctorByRybh/list")
    @ResponseBody
    public List<ZfYyjlbEntity> findDoctorByRybh(String jsbh, String rybh) {
        return repository.findDoctorByJsbhAndRybh(jsbh, rybh);
    }

    @RequestMapping("/yyjl/save")
    @ResponseBody
    public boolean save(ZfYyjlbEntity meeting) {
        Date date = new Date();
        //生成主键--------
        String oldId = repository.findZybh();
        meeting.setZybh(ToolUtils.CreatePrimaryKey(oldId));
        meeting.setYysj(date);
        meeting.setCjsj(date);
        meeting.setJsmc("");
        Byte b=0;
        meeting.setScbj(b);
        repository.save(meeting);
        return true;
    }

//    public static String convert2Id12(Date date) {
//        if (date == null) {
//            return null;
//        }
//        return DateFormatUtils.format(date, "yyMMdd")
//                + String.format("%06x", nextInc.incrementAndGet() & 0x00FFFFFF);
//    }

    private static AtomicInteger nextInc = new AtomicInteger((new java.util.Random()).nextInt());

}
